<?php

error_reporting(E_ALL);

/**
 * Cegelec 2 Renewed - class.db_locatie.php
 *
 * $Id$
 *
 * This file is part of Cegelec 2 Renewed.
 *
 * Automatically generated on 25.06.2015, 11:05:47 with ArgoUML PHP module 
 * (last revised $Date: 2010-01-12 20:14:42 +0100 (Tue, 12 Jan 2010) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */


/**
 * include database
 *
 * @author firstname and lastname of author, <author@example.org>
 */


/* user defined includes */
// section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EE2-includes begin
// section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EE2-includes end

/* user defined constants */
// section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EE2-constants begin
require_once FILE_DB;
// section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EE2-constants end

/**
 * Short description of class db_locatie
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class dbLocatie
    extends database
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute locatie_id
     *
     * @access public
     * @var integer
     */
    public $locatie_id = null;

    /**
     * Short description of attribute locatie_naam
     *
     * @access public
     * @var string
     */
    public $locatie_naam = '';

    /**
     * Short description of attribute locatie_status
     *
     * @access public
     * @var boolean
     */
    public $locatie_status = false;

    /**
     * Short description of attribute locatie_gegevens
     *
     * @access public
     * @var string
     */
    public $locatie_gegevens = '';

    // --- OPERATIONS ---

    /**
     * Short description of method __construct
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function __construct()
    {
        // section -84-19-77--37-7deb09e9:14e29ef8f61:-8000:0000000000000F2A begin
        parent::__construct();
        // section -84-19-77--37-7deb09e9:14e29ef8f61:-8000:0000000000000F2A end
    }

    /**
     * Short description of method addLocatieDb
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  locatie
     * @return mixed
     */
    public function addLocatieDb($locatie)
    {
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EEF begin
        $query = "INSERT INTO `locatie`(
                `locatie_naam` ,
                `locatie_beschrijving`
                )
                  VALUES (
                '" . $this->dbInString($locatie->getLocatieNaam()) . "',   
                '" . $this->dbInString($locatie->getLocatieBeschrijving() ) . "'
                )";
        
    
        
        if (!$this->dbquery($query)) {
            return false;
        } else {
            $this->locatie_naam = $locatie->getLocatieNaam();
            $this->locatie_beschrijving = $locatie->getLocatieBeschrijving();
            //$this->locatie_id = $locatie->setLocatieId();
            return true;
        }
    
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EEF end
    }

    /**
     * Short description of method getLocatieListDb
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function getLocatieListDb()
    {
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF1 begin
        $query = "SELECT * FROM `locatie` ORDER BY `locatie_id` ASC";
               
        if (!$this->dbquery($query)) {
            return false;
        }
        if (!($result = $this->dbFetchAll())) {
            // set error.
            echo TXT_NO_DATA;
            return FALSE;
        }
        
        foreach($result as $idx => $row){
            $locatie_object[$row['locatie_id']] = new locatie();
            
            $locatie_object[$row['locatie_id']]->setLocatieBeschrijving($this->dbOutString($row['locatie_beschrijving']));
            $locatie_object[$row['locatie_id']]->setLocatieNaam($this->dbOutString($row['locatie_naam']));
            $locatie_object[$row['locatie_id']]->setLocatieId((int)$row['locatie_id']);
            
          
            
        }
        return $locatie_object;
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF1 end
    }

    /**
     * Short description of method getLocatieByName
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  locatieNaam
     * @return mixed
     */
    public function getLocatieByName($locatieNaam)
    {
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF3 begin
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF3 end
    }

    /**
     * Short description of method getLocatieByIdDb
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  locatie_id
     * @return mixed
     */
    public function getLocatieByIdDb($id)
    {
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF5 begin
        $query = "SELECT * FROM `locatie` WHERE `locatie_id` = '". $id . "'";
        
        if (!$this->dbquery($query)) {
            return false;
        }
        
       if (!($result = $this->dbFetchAll())) {
            // set error.
            echo TXT_NO_DATA;
            return FALSE;
        }
        
        foreach($result as $idx => $row){
            $locatie = new Locatie();
            $locatie->setLocatieId($row['locatie_id']);
            $locatie->setLocatieNaam($row['locatie_naam']);
            $locatie->setLocatieBeschrijving($row['locatie_beschrijving']);
        }
        return $locatie;
        // section -84-19-82--123-1a43ac82:14e0569be64:-8000:0000000000000EF5 end
    }

    /**
     * Short description of method updateLocatieDb
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param  locatie
     * @return mixed
     */
    public function updateLocatieDb($locatie)
    {
        // section -84-19-77--37-7deb09e9:14e29ef8f61:-8000:0000000000000F27 begin
        $query = "UPDATE `locatie`
                SET `locatie_naam` = '" . $this->dbInString($locatie->getLocatieNaam()) . "',
                    `locatie_beschrijving` = '" . $this->dbInString($locatie->getLocatieBeschrijving()) . "'
                WHERE
                    `locatie_id`= '" . $this->dbInString($locatie->getLocatieId()) . "'";
                
        
        if (!$this->dbquery($query)) {
            return false;
        } else {
            header('Location: '. 'index.php?page=leerling&subpage=locatielijst' );
            return true;
        }
        // section -84-19-77--37-7deb09e9:14e29ef8f61:-8000:0000000000000F27 end
    }

} /* end of class db_locatie */

?>